package com.qianchang.microfinance.view.yfbpay;

import android.os.Bundle;
import android.view.View;

import com.dm.library.http.DMOKHttpUtils;
import com.dm.library.http.HttpParams;
import com.dm.library.http.base.JsonResult;
import com.dm.library.http.callback.RequestCallBack;
import com.dm.library.utils.ToastUtil;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.ThpinfoBean;
import com.qianchang.microfinance.global.DMApplication;
import com.qianchang.microfinance.utils.DMConstant;
import com.qianchang.microfinance.view.base.BaseActivity;

import butterknife.ButterKnife;
import butterknife.OnClick;


/****
 * 易宝支付 解绑银行卡
 */


public class YBUntiedBankCardActivity extends BaseActivity{

    private static int UNTIED_RESCODE = 4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yfbuntiedbankcard_layout);
        ButterKnife.bind(this);
        initView();

    }


    @Override
    protected void initView() {
        super.initView();
        setTitle("解绑银行卡");

    }



    @OnClick({R.id.bt_payapply_id})
    public void onViewClicked(View view) {
        int vId = view.getId();
        switch (vId){
            case R.id.bt_payapply_id:           //解绑银行卡

                tlUntiedBankCard();

//                isUntiedSus = true;
//                TlUntiedBankCardActivity.this.finish();

                break;
            default:
                break;
        }
    }

    private boolean isUntiedSus = false;

    //解绑银行卡
    private void tlUntiedBankCard(){

        String userId = DMApplication.getInstance().getmUserLoginInfo().getUserId();
        HttpParams params = new HttpParams();
        params.put("agreeid",userId);
        params.put("meruserid",userId);
        params.put("userId",userId);

        show();
        DMOKHttpUtils.getInstance().post(YBUntiedBankCardActivity.this, DMConstant.ApiURL.TL_BNKCARDUNBINDING, params, new RequestCallBack<ThpinfoBean>() {

            @Override
            public void onSuccess(JsonResult<ThpinfoBean> response) {
                dismiss();
                if (DMConstant.Code.CODE_OK.equals(response.getCode())) {
                    isUntiedSus = true;
                    if(isUntiedSus){                        //如果解绑成功设置回调在 TLPayActivity 刷新页面
                        setResult(UNTIED_RESCODE);
                    }
                    toReSult();
                    YBUntiedBankCardActivity.this.finish();
                }else {
                    isUntiedSus = false;
                    ToastUtil.getInstant().show(YBUntiedBankCardActivity.this, response.getDescription());
                }
            }

            @Override
            public void onFailure(String msg) {
                dismiss();
                isUntiedSus = false;
                ToastUtil.getInstant().show(YBUntiedBankCardActivity.this, msg);
            }

            @Override
            public void onConnectFailure(String msg) {
            }
        });
    }





    private void toReSult(){
        Bundle bundle = new Bundle();
        bundle.putInt("typeInt",3);
        startActivity(YBSusOrFailActivity.class,bundle);
    }


}
